package com.dnjn.happiness.system.api.factory;

import com.dnjn.happiness.common.core.model.PositionLadderVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.dnjn.happiness.common.core.domain.R;
import com.dnjn.happiness.system.api.RemoteUserService;
import com.dnjn.happiness.system.api.domain.SysUser;
import com.dnjn.happiness.system.api.model.LoginUser;

import java.util.List;
import java.util.Map;

/**
 * 用户服务降级处理
 * 
 * @author happiness
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<SysUser> getUserByEmpno(String empno, String source) {
                return R.fail("根据工号获取所有用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> checkUserIsManager(Long userId, String source) {
                return R.fail("校验用户是否管理者失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> selectByLimit(Integer page, int pageSize, String source) {
                return R.fail("查询用户分页列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> getUserCount(String source) {
                return R.fail("查询用户总条数失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getUserListAll(String source) {
                return R.fail("获取所有用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> getUserByUnId(String id, String source) {
                return R.fail("获取用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> selectUserByEmpnoAndUserName(String empno, String username, String source) {
                return R.fail("获取用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> selectUserById(Long userId, String source) {
                return R.fail("获取用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> selectUserInfo(Long userId, String source) {
                return R.fail("获取用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> selectUserList(SysUser sysUser, String source) {
                return R.fail("获取用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getUsersByPostId(Map<String, Object> map, String source) {
                return R.fail("获取岗位用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getUsersByPosition(Map<String, Object> map, String source) {
                return R.fail("获取职级用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Long>> selectUserListByDeptIdList(Long userId, String source) {
                return R.fail("根据部门id获取用户id列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> getUsersByDeptIdList(List<Long> deptIdList, String source) {
                return R.fail("获取用户id失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> getCommunicationCount(Integer num, List<Long> deptIdList, String source) {
                return R.fail("获取人数失败:" + throwable.getMessage());
            }

            @Override
            public R<List<PositionLadderVO>> queryPositionListByDeptId(Long deptId, String source) {
                return R.fail("获取职级列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> selectUserCount(Long deptId, String source) {
                return R.fail("获取人数失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> queryUserListByDeptId(Long currtDeptId, String nickName, String source) {
                return R.fail("获取用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> selectUsersByLeaderId(Long leaderId, String source) {
                return  R.fail("获取用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> selectUserAndScore(Long userId, String source) {
                return R.fail("获取用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }
        };
    }
}
